$(function(){
	$(document).on("tap",".ui-cell-title-slidebtn", function(){
		var obj = $(this).parents(".ui-cell-title").next(".ui-cell-list");
		var h = obj.height();
		if(!obj.attr("data-h")){
			obj.attr("data-h", h);
		}
		if(h > 5){
			$(this).animate({
				rotate: "180deg"
			}, 300, "ease-out")
			obj.animate({
				height: '0px'
			}, 300, 'ease-out');
		}else{
			obj.animate({
				height: obj.attr("data-h") + "px"
			}, 300, 'ease-out');
			$(this).animate({
				rotate: "0deg"
			}, 300, "ease-out")
		}
	})

	$(document).on("touchmove",".ui-modal-large", function(e){
		e.stopPropagation();
	})

	$(document).on("tap",".ui-banner-btn", function(e){
		$(".ui-modal-large").show();
		setTimeout(function(){
			$(".ui-modal-large").animate({
				translateX: 0
			}, 300, 'ease-out', function(){
				$(".ui-page").hide();
			});
		}, 300)
	})

	$(document).on("tap",".city-back", function(e){
		$(".ui-page").show();
		setTimeout(function(){
			$(".ui-modal-large").animate({
				translateX: "100%"
			}, 300, 'ease-out');
		}, 300, function(){
			$(".ui-modal-large").hide();
		});
	})
	$(document).on("tap",".ui-btn-yuyue", function(e){
		if(!$(this).hasClass("disabled")){
			$(".ui-btn-yuyue.checked").not(".disabled").find("font").html("可预约")
			$(".ui-btn-yuyue").removeClass("checked");
			$(this).addClass("checked");
			$(this).not(".disabled").find("font").html("已选");
		}
	})
	$(document).on("tap",".ui-input-clear", function(e){
		$(this).prev("input").val("").focus();
	})

	$(document).on("touchmove", ".move-forbidden", function(e){
		e.preventDefault();
	})
})

$.fn.toast = {
	loading: function(){
		if($(".loading-mask").length<=0){
			var html = '<div class="loading-mask move-forbidden"><div class="loading-wrap"><div class="weui_loading"><div class="weui_loading_leaf weui_loading_leaf_0"></div><div class="weui_loading_leaf weui_loading_leaf_1"></div><div class="weui_loading_leaf weui_loading_leaf_2"></div><div class="weui_loading_leaf weui_loading_leaf_3"></div><div class="weui_loading_leaf weui_loading_leaf_4"></div><div class="weui_loading_leaf weui_loading_leaf_5"></div><div class="weui_loading_leaf weui_loading_leaf_6"></div><div class="weui_loading_leaf weui_loading_leaf_7"></div><div class="weui_loading_leaf weui_loading_leaf_8"></div><div class="weui_loading_leaf weui_loading_leaf_9"></div><div class="weui_loading_leaf weui_loading_leaf_10"></div><div class="weui_loading_leaf weui_loading_leaf_11"></div></div><div class="loading-txt">数据加载中</div></div></div>';
			$("body").append(html);
		}else{
			$(".loading-mask").show();
		}
	},
	loadingHide: function(){
		$(".loading-mask").hide();
	},
	success: function(str, timer){
		str = typeof(str) == "undefined" ? "已完成" : str;
		timer = typeof(timer) == "undefined" ? 2000 : timer;
		if($(".success-mask").length<=0){
			var html = '<div class="success-mask move-forbidden"><div class="success-wrap"><div class="success-icon"><i class="ui_icon_toast"></i></div><div class="success-txt">'+str+'</div></div></div>';
			$("body").append(html);
		}else{
			$(".success-txt").html(str);
			$(".success-mask").show();
		}

		setTimeout(function(){
			$(".success-mask").hide();
		}, 1000);
	},
	alert: function(str, func){
		str = typeof(str) == "undefined" ? "已完成" : str;
		if($(".alert-mask").length<=0){
			var html = '<div class="alert-mask move-forbidden"><div class="alert-wrap"><div class="alert-txt"><p>'+str+'</p></div><div class="alert-btn">确定</div></div></div>';
			$("body").append(html);
			$(".alert-wrap").animate({
				translateY: 0
			}, 200);
		}else{
			$(".alert-txt p").html(str)
			$(".alert-mask").show();
			$(".alert-wrap").animate({
				translateY: 0
			}, 200);
		}

		$(document).on("tap", ".alert-btn", function(e){
			setTimeout(function(){
				$(".alert-mask").hide();
				$(".alert-wrap").animate({
					translateY: "-300%"
				}, 300);
				if(typeof(func) === 'function'){
					func.call();
				}
			}, 400);
		});
	}
}